import numpy as np
import pandas as pd
import datetime

dates=pd.date_range('20170301',periods=8)
df=pd.DataFrame(np.random.randn(8,5),index=dates,columns=list('ABCDE'))
print(df.mean())
print(df.var())
s=pd.Series([1,2,4,np.nan,5,7,9,10],index=dates)
print(s)
print(s.shift(2))
print(s.diff())
print(s.value_counts())
print(df.apply(np.cumsum))
print(df.apply(lambda x:x.max()-x.min()))

pieces=[df[:3],df[-3:]]
print(pd.concat(pieces))
left=pd.DataFrame({'key':['x','y'],'value':[1,2]})
right=pd.DataFrame({'key':['x','z'],'value':[3,4]})
print(left)
print(right)
print(pd.merge(left,right,on='key',how='outer'))
df3=pd.DataFrame({'A':['a','b','c','b'],'B':list(range(4))})
print(df3.groupby('A').sum())

df4=pd.DataFrame({'A':['one','one','two','three']*6,
                  'B':['a','b','c']*8,
                  'C':['foo','foo','foo','bar','bar','bar']*4,
                  'D':np.random.randn(24),
                  'E':np.random.randn(24),
                  'F':[datetime.datetime(2017,i,1) for i in range(1,13)]+
                      [datetime.datetime(2017,i,15) for i in range(1,13)]})
print(pd.pivot_table(df4,values='D',index=['A','B'],columns=['C']))
